package com.bjsxt.livegoods.dao.banner;

import org.springframework.beans.factory.annotation.Autowired;
import com.bjsxt.livegoods.entity.Banner;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class BannerDaoImpl implements BannerDao{

    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public List<Banner> findBanners() {
        Query query=new Query();
        query.with(PageRequest.of(0,8));
        List<Banner> result=mongoTemplate.find(query,Banner.class);
        return result;
    }

    @Override
    public void insertBanner(Banner banner) {
        this.mongoTemplate.insert(banner);
    }

    public MongoTemplate getMongoTemplate() {
        return mongoTemplate;
    }

    public void setMongoTemplate(MongoTemplate mongoTemplate) {
        this.mongoTemplate = mongoTemplate;
    }
}
